// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import store, { GAME_STATE } from './common'

const { ccclass, property } = cc._decorator;

@ccclass
export default class Scroller extends cc.Component {

    @property
    speed: number = 0;

    @property
    resetX: number = 0;

    update(dt) {
        if (store.state == GAME_STATE.OVER) {
            return;
        }

        var x = this.node.x;
        x += this.speed * dt;
        if (x <= this.resetX) {
            x -= this.resetX;
        }
        this.node.x = x;
    }
}
